package com.auth.control.base;


import com.redis.sdk.cachecore.CacheRedisDelete;
import com.auth.common.constant.RedisKey;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.auth.control.model.AuthDto;
import com.auth.domain.module.vo.authmanage.AuthVO;
import com.auth.domain.service.IAuthService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author cyj
 * @since 2020-10-20
 */
@RestController
@RequestMapping("/auth")
@Slf4j
@Api(tags = "权限")
public class AuthController {

    @Autowired
    private IAuthService roleService;

    @GetMapping("/all")
    @ApiOperation("获取权限分页")
    public IPage<AuthVO> getAuths(Page page) {
        IPage<AuthVO> page1 = roleService.getAuths(page);
        return page1;
    }

    @PostMapping
    @ApiOperation("保存权限")
    @CacheRedisDelete(value = "", prefix = RedisKey.AUTHCACHE)
    public AuthVO saveAuth(@RequestBody AuthDto authDto) {
        AuthVO role = roleService.saveAuth(authDto);
        return role;
    }

    @PutMapping
    @ApiOperation("更新权限")
    @CacheRedisDelete(value = "", prefix = RedisKey.AUTHCACHE)
    public AuthVO updateAuth(@RequestBody AuthDto authDto) {
        AuthVO role = roleService.updateAuth(authDto);
        return role;
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除权限")
    @CacheRedisDelete(value = "", prefix = RedisKey.AUTHCACHE)
    public AuthVO deleteAuth(@PathVariable Long id) {
        AuthVO role = roleService.deleteAuth(id);
        return role;
    }

    @GetMapping("/{id}")
    @ApiOperation("查询权限")
    public AuthVO selectAuth(@PathVariable Long id) {
        AuthVO role = roleService.selectAuth(id);
        return role;
    }

}

